package com.visualize.demo.service;

import com.visualize.demo.model.FiveEmotion;
import com.visualize.demo.model.FiveEmotionPercent;
import com.visualize.demo.model.JsonResponse;
import com.visualize.demo.repository.FiveEmotionRepository;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FiveEmotionService extends BaseService {
    private final FiveEmotionRepository fiveEmotionRepository;

    public FiveEmotionService(FiveEmotionRepository fiveEmotionRepository) {
        this.fiveEmotionRepository = fiveEmotionRepository;
    }

    public JsonResponse getData(String sTime, String eTime) {
        List<FiveEmotion> emotionList = fiveEmotionRepository.getFiveEmotionsByTime(parseDate(sTime), parseDate(eTime));
        Map<String, List<FiveEmotion>> content = new HashMap<>();
        content.put("list", emotionList);
        return new JsonResponse(200, content);
    }

    public JsonResponse getPercentData(String sTime, String eTime) {
        List<FiveEmotion> emotionList = fiveEmotionRepository.getFiveEmotionsByTime(parseDate(sTime), parseDate(eTime));
        List<FiveEmotionPercent> list = new ArrayList<>();
        for (FiveEmotion fiveEmotion : emotionList) {
            list.add(new FiveEmotionPercent(
                    fiveEmotion.getNum(),
                    fiveEmotion.getGrief(),
                    fiveEmotion.getEvil(),
                    fiveEmotion.getHappiness(),
                    fiveEmotion.getFear(),
                    fiveEmotion.getAnger(),
                    fiveEmotion.getTime()
            ));
        }
        Map<String, List<FiveEmotionPercent>> content = new HashMap<>();
        content.put("list", list);
        return new JsonResponse(200, content);
    }

}
